using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;

namespace TBOAzMan
{

    class DBManager
    {
        SqlConnection conn;
        SqlCommand comm;
        
        public DBManager()
        {
            conn = new SqlConnection(ConfigurationManager.ConnectionStrings["TBOAzMan.Properties.Settings.AzManDBConnectionString"].ConnectionString);
            comm = new SqlCommand();
            comm.Connection = conn;
            comm.CommandType = System.Data.CommandType.StoredProcedure;
        }

        public void PlaceOrder(String name, int amount, String empName, String comName)
        {
            if(comName == null) comName = "";
            comm.CommandText = "PlaceOrder";
            comm.Parameters.Clear();
            comm.Parameters.Add(new SqlParameter("@Name", name));
            comm.Parameters.Add(new SqlParameter("@Amount", amount));
            comm.Parameters.Add(new SqlParameter("@EmployeeName", empName));
            comm.Parameters.Add(new SqlParameter("@CommiterName", comName));

            conn.Open();
            comm.ExecuteNonQuery();
            conn.Close();
        }

        public void CommitOrder(int order_id, String commiterName)
        {
            comm.CommandText = "CommitOrder";
            comm.Parameters.Clear();
            comm.Parameters.Add(new SqlParameter("@Order_id", order_id));
            comm.Parameters.Add(new SqlParameter("@CommiterName", commiterName));

            conn.Open();
            comm.ExecuteNonQuery();
            conn.Close();
        }
    }
}
